package huixue.cn.com.rxapp.rx.presenter;

import android.Manifest;

import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;

import huixue.cn.com.library.util.ToastUtils;
import huixue.cn.com.rxapp.base.BaseCoreActivity;
import huixue.cn.com.rxapp.base.BasePresent;
import huixue.cn.com.rxapp.base.IBaseUI;
import io.reactivex.functions.Consumer;

/**
 * Created by gongdongyang 2019/7/18
 * Describe:
 */
public class MainPresenter extends BasePresent<MainPresenter.MainUI> {

    public interface MainUI extends IBaseUI{

    }

    @Override
    public void onUIReady(BaseCoreActivity activity, MainUI ui) {
        super.onUIReady(activity, ui);

        final RxPermissions rxPermissions = new RxPermissions(getActivity());

        rxPermissions.requestEach(Manifest.permission.READ_PHONE_STATE,Manifest.permission.CAMERA).subscribe(new Consumer<Permission>() {
            @Override
            public void accept(Permission permission) throws Exception {
                if (permission.granted) {
                    // 用户已经同意该权限
                    ToastUtils.showToast("用户已经同意该权限");
                } else if (permission.shouldShowRequestPermissionRationale) {
                    // 用户拒绝了该权限，没有选中『不再询问』（Never ask again）,那么下次再次启动时，还会提示请求权限的对话框
                    ToastUtils.showToast("用户拒绝了该权限");
                } else {
                    // 用户拒绝了该权限，并且选中『不再询问』，提醒用户手动打开权限
                    ToastUtils.showToast ("权限被拒绝，请在设置里面开启相应权限，若无相应权限会影响使用");
                }
            }
        });
    }
}
